package com.hlhj.funlike_business.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hlhj.funlike_business.R;
import com.hlhj.funlike_business.bean.MsgBean;
import com.hlhj.funlike_business.data.SPUser;
import com.hlhj.funlike_business.presenter.AdvertPresenter;
import com.hlhj.funlike_business.views.AdvertView;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

public class AdvertAty extends BaseActivity<AdvertView,AdvertPresenter> implements AdvertView {
    private EditText ed_advert;
    private ImageView img_back;
    private TextView tv_title,btn_ok;
    private String advert;
    @Override
    protected int getContentId() {
        return R.layout.aty_advert;
    }

    @Override
    protected void initData() {
        tv_title.setText("广告语");
        advert = getIntent().getStringExtra("advert");
    }

    @NotNull
    @Override
    public AdvertView bindView() {
        return this;
    }

    @NotNull
    @Override
    public AdvertPresenter createPresenter() {
        return new AdvertPresenter();
    }

    @Override
    public void initView() {
        ed_advert=findViewById(R.id.ed_advert);
        img_back=findViewById(R.id.img_back);
        tv_title=findViewById(R.id.tv_title);
        btn_ok=findViewById(R.id.btn_ok);
    }

    @Override
    public void logicStart() {
        ed_advert.setText(advert);
    }

    @Override
    public void setListener() {
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null!=ed_advert.getText().toString() || !"".equals(ed_advert.getText().toString())){
                    getPresenter().LoadResult(AdvertAty.this,ed_advert.getText().toString());
                }else {
                    Toast.makeText(AdvertAty.this,"请输入广告语",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    public void showResult(MsgBean msgBean) {
        new SPUser(getApplication()).setShopAdvert(ed_advert.getText().toString());
        Toast.makeText(AdvertAty.this,msgBean.getMsg().toString(),Toast.LENGTH_SHORT).show();
        EventBus.getDefault().post("刷新");
        finish();
    }
}
